from fastapi import APIRouter
from starlette.requests import Request
from core.logger.proxy import logger
from service.chat import ChatService
from infrax.queue import message_queue


chat_router = APIRouter(prefix="/chat")


@chat_router.get("/message")
async def message(request: Request):
    mp = request.query_params.get("message", "unknown message")
    c = ChatService(name="yusl007-0805-05")
    r = {
        "code": 200,
        "status": "success",
        "data": {
            "message": mp,
            "username": c.get_username(),
        },
    }
    message_queue.write(r)
    return r
